VFG.ConeSatellite=function(viewer, options) {
	this.viewer = viewer;
	this.options = options;
	this.id= options.id;
	this.name= options.name;
	this.position=options.position||null;
	this.orientation=options.orientation||{};
	this.model=options.model||{};
	this.init();
}
VFG.ConeSatellite.prototype.init = function() {
	let _this=this;
	var param={
			id: this.id,
			name :this.name,
			url :this.model.url||'',
			modelMatrix : this.getModelMatrix(),
			scale :this.model.scale*1||1,
			show : this.model.show||true,   
			minimumPixelSize:this.model.minimumPixelSize||0,
			allowPicking : this.model.allowPicking||true,        
			debugShowBoundingVolume : this.model.debugShowBoundingVolume||false, 
			debugWireframe : this.model.debugWireframe||false, 
			backFaceCulling:this.model.backFaceCulling||false, 
			shadows: this.model.shadows||false,   
	}
	if('1'== this.model.distanceDisplayCondition){
		param.distanceDisplayCondition=VFG.Util.getDistanceDisplayCondition( this.model.distanceNear, this.model.distanceFar);	
	}
	if('1'== this.model.silhouette){
		param.silhouetteColor= this.model.silhouetteColor? Cesium.Color.fromCssColorString( this.model.silhouetteColor):Cesium.Color.BLACK;	
		param.silhouetteSize= this.model.silhouetteSize*1||0;	
	}
	if('1'== this.model.fill){
		param.color= this.model.fillColor? Cesium.Color.fromCssColorString( this.model.fillColor):Cesium.Color.BLACK;	
	}
	this.primity = this.viewer.scene.primitives.add(Cesium.Model.fromGltf(param));
	this.primity.readyPromise.then(function(model) {
		if(_this.success){
			_this.success(model)
		}
	}).otherwise(function(error){
		if(_this.error){
			_this.error(error);
		}
    });
};
VFG.ConeSatellite.prototype.getModelMatrix=function(){
    var hpRoll = new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(this.orientation.heading || 0), Cesium.Math.toRadians(this.orientation.pitch || 0), Cesium.Math.toRadians(this.orientation.roll || 0));
    var fixedFrameTransform = Cesium.Transforms.eastNorthUpToFixedFrame;
    let cartesian3=Cesium.Cartesian3.fromDegrees(this.position.x*1, this.position.y*1,this.position.z*1);
    var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(cartesian3, hpRoll, this.viewer.scene.globe.ellipsoid, fixedFrameTransform);
    return modelMatrix;
}

VFG.ConeSatellite.prototype.getRadius=function(){
    return this.primity.boundingSphere.radius;
}


VFG.ConeSatellite.prototype.on=function(type,callback){
	if('success'==type){
		this.success=callback;
	}
	if('error'==type){
		this.error=callback;
	}
}
VFG.ConeSatellite.prototype.update=function(options){
}

VFG.ConeSatellite.prototype.updatePosition=function(position){
	this.position=position;
	if(this.primity){
		this.primity.modelMatrix=this.getModelMatrix();
	}
}

VFG.ConeSatellite.prototype.updateHeading=function(heading){
	this.orientation.heading=heading;
	if(this.primity){
		this.primity.modelMatrix=this.getModelMatrix();
	}
}


VFG.ConeSatellite.prototype.updatePosition=function(position){
	this.position=position;
	if(this.primity){
		this.primity.modelMatrix=this.getModelMatrix();
	}
}


VFG.ConeSatellite.prototype.destroy = function() {
	if(this.primity){
		this.viewer.scene.primitives.remove(this.primity);
	}
	delete this.orientation
	delete this.position
	delete this.primity
	delete this.options
	delete this.model
    delete this.viewer
	return Cesium.destroyObject(this);
};
